.class public Lrexsee/security/RexseeSignature;
.super Ljava/lang/Object;
.source "RexseeSignature.java"

# interfaces
.implements Lrexsee/core/browser/clazz/JavascriptInterface;


# static fields
.field private static final INTERFACE_NAME:Ljava/lang/String; = "Signature"


# instance fields
.field private final mBrowser:Lrexsee/core/browser/Browser;


# direct methods
.method public constructor <init>(Lrexsee/core/browser/Browser;)V
    .locals 0
    .param p1, "browser"    # Lrexsee/core/browser/Browser;

    .prologue
    .line 37
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 38
    iput-object p1, p0, Lrexsee/security/RexseeSignature;->mBrowser:Lrexsee/core/browser/Browser;

    .line 39
    return-void
.end method

.method private signDSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;
    .locals 6
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "privateKey"    # Ljava/lang/String;
    .param p3, "string"    # Ljava/lang/String;
    .param p4, "isFile"    # Z

    .prologue
    .line 70
    if-eqz p4, :cond_0

    invoke-static {p3}, Lrexsee/core/utilities/Utilities;->getContent(Ljava/lang/String;)[B

    move-result-object v4

    move-object v0, v4

    .line 71
    .local v0, "data":[B
    :goto_0
    if-nez v0, :cond_1

    const-string v4, "[Exception]Error on reading source data."

    .line 79
    :goto_1
    return-object v4

    .line 70
    .end local v0    # "data":[B
    :cond_0
    invoke-virtual {p3}, Ljava/lang/String;->getBytes()[B

    move-result-object v4

    move-object v0, v4

    goto :goto_0

    .line 73
    .restart local v0    # "data":[B
    :cond_1
    :try_start_0
    invoke-static {p1}, Ljava/security/Signature;->getInstance(Ljava/lang/String;)Ljava/security/Signature;

    move-result-object v3

    .line 74
    .local v3, "signature":Ljava/security/Signature;
    const-string v4, "DSA"

    invoke-static {v4, p2}, Lrexsee/security/RexseeSignature;->string2privateKey_(Ljava/lang/String;Ljava/lang/String;)Ljava/security/PrivateKey;

    move-result-object v2

    check-cast v2, Ljava/security/interfaces/DSAPrivateKey;

    .line 75
    .local v2, "key":Ljava/security/interfaces/DSAPrivateKey;
    invoke-virtual {v3, v2}, Ljava/security/Signature;->initSign(Ljava/security/PrivateKey;)V

    .line 76
    invoke-virtual {v3, v0}, Ljava/security/Signature;->update([B)V

    .line 77
    invoke-virtual {v3}, Ljava/security/Signature;->sign()[B

    move-result-object v4

    invoke-static {v4}, Lrexsee/security/RexseeSecurity;->bytes2hex([B)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v4

    goto :goto_1

    .line 78
    .end local v2    # "key":Ljava/security/interfaces/DSAPrivateKey;
    .end local v3    # "signature":Ljava/security/Signature;
    :catch_0
    move-exception v4

    move-object v1, v4

    .line 79
    .local v1, "e":Ljava/lang/Exception;
    new-instance v4, Ljava/lang/StringBuilder;

    const-string v5, "[Exception]"

    invoke-direct {v4, v5}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v1}, Ljava/lang/Exception;->getLocalizedMessage()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    goto :goto_1
.end method

.method private signRSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;
    .locals 6
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "privateKey"    # Ljava/lang/String;
    .param p3, "string"    # Ljava/lang/String;
    .param p4, "isFile"    # Z

    .prologue
    .line 57
    if-eqz p4, :cond_0

    invoke-static {p3}, Lrexsee/core/utilities/Utilities;->getContent(Ljava/lang/String;)[B

    move-result-object v4

    move-object v0, v4

    .line 58
    .local v0, "data":[B
    :goto_0
    if-nez v0, :cond_1

    const-string v4, "[Exception]Error on reading source data."

    .line 66
    :goto_1
    return-object v4

    .line 57
    .end local v0    # "data":[B
    :cond_0
    invoke-virtual {p3}, Ljava/lang/String;->getBytes()[B

    move-result-object v4

    move-object v0, v4

    goto :goto_0

    .line 60
    .restart local v0    # "data":[B
    :cond_1
    :try_start_0
    invoke-static {p1}, Ljava/security/Signature;->getInstance(Ljava/lang/String;)Ljava/security/Signature;

    move-result-object v3

    .line 61
    .local v3, "signature":Ljava/security/Signature;
    const-string v4, "RSA"

    invoke-static {v4, p2}, Lrexsee/security/RexseeSignature;->string2privateKey_(Ljava/lang/String;Ljava/lang/String;)Ljava/security/PrivateKey;

    move-result-object v2

    check-cast v2, Ljava/security/interfaces/RSAPrivateKey;

    .line 62
    .local v2, "key":Ljava/security/interfaces/RSAPrivateKey;
    invoke-virtual {v3, v2}, Ljava/security/Signature;->initSign(Ljava/security/PrivateKey;)V

    .line 63
    invoke-virtual {v3, v0}, Ljava/security/Signature;->update([B)V

    .line 64
    invoke-virtual {v3}, Ljava/security/Signature;->sign()[B

    move-result-object v4

    invoke-static {v4}, Lrexsee/security/RexseeSecurity;->bytes2hex([B)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v4

    goto :goto_1

    .line 65
    .end local v2    # "key":Ljava/security/interfaces/RSAPrivateKey;
    .end local v3    # "signature":Ljava/security/Signature;
    :catch_0
    move-exception v4

    move-object v1, v4

    .line 66
    .local v1, "e":Ljava/lang/Exception;
    new-instance v4, Ljava/lang/StringBuilder;

    const-string v5, "[Exception]"

    invoke-direct {v4, v5}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v1}, Ljava/lang/Exception;->getLocalizedMessage()Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    goto :goto_1
.end method

.method private static string2privateKey_(Ljava/lang/String;Ljava/lang/String;)Ljava/security/PrivateKey;
    .locals 4
    .param p0, "algorithm"    # Ljava/lang/String;
    .param p1, "key"    # Ljava/lang/String;

    .prologue
    .line 43
    :try_start_0
    invoke-static {p0}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;

    move-result-object v1

    new-instance v2, Ljava/security/spec/PKCS8EncodedKeySpec;

    invoke-static {p1}, Lrexsee/security/RexseeSecurity;->decodeKey(Ljava/lang/String;)[B

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/security/spec/PKCS8EncodedKeySpec;-><init>([B)V

    invoke-virtual {v1, v2}, Ljava/security/KeyFactory;->generatePrivate(Ljava/security/spec/KeySpec;)Ljava/security/PrivateKey;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    .line 45
    :goto_0
    return-object v1

    .line 44
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 45
    .local v0, "e":Ljava/lang/Exception;
    const/4 v1, 0x0

    goto :goto_0
.end method

.method private static string2publicKey_(Ljava/lang/String;Ljava/lang/String;)Ljava/security/PublicKey;
    .locals 4
    .param p0, "algorithm"    # Ljava/lang/String;
    .param p1, "key"    # Ljava/lang/String;

    .prologue
    .line 50
    :try_start_0
    invoke-static {p0}, Ljava/security/KeyFactory;->getInstance(Ljava/lang/String;)Ljava/security/KeyFactory;

    move-result-object v1

    new-instance v2, Ljava/security/spec/X509EncodedKeySpec;

    invoke-static {p1}, Lrexsee/security/RexseeSecurity;->decodeKey(Ljava/lang/String;)[B

    move-result-object v3

    invoke-direct {v2, v3}, Ljava/security/spec/X509EncodedKeySpec;-><init>([B)V

    invoke-virtual {v1, v2}, Ljava/security/KeyFactory;->generatePublic(Ljava/security/spec/KeySpec;)Ljava/security/PublicKey;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    .line 52
    :goto_0
    return-object v1

    .line 51
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 52
    .local v0, "e":Ljava/lang/Exception;
    const/4 v1, 0x0

    goto :goto_0
.end method

.method private verifyDSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Z
    .locals 7
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "publicKey"    # Ljava/lang/String;
    .param p3, "signatureString"    # Ljava/lang/String;
    .param p4, "string"    # Ljava/lang/String;
    .param p5, "isFile"    # Z

    .prologue
    const/4 v6, 0x0

    .line 98
    if-eqz p5, :cond_0

    invoke-static {p4}, Lrexsee/core/utilities/Utilities;->getContent(Ljava/lang/String;)[B

    move-result-object v5

    move-object v0, v5

    .line 99
    .local v0, "data":[B
    :goto_0
    if-nez v0, :cond_1

    move v5, v6

    .line 109
    :goto_1
    return v5

    .line 98
    .end local v0    # "data":[B
    :cond_0
    invoke-virtual {p4}, Ljava/lang/String;->getBytes()[B

    move-result-object v5

    move-object v0, v5

    goto :goto_0

    .line 100
    .restart local v0    # "data":[B
    :cond_1
    invoke-static {p3}, Lrexsee/security/RexseeSecurity;->hex2bytes(Ljava/lang/String;)[B

    move-result-object v3

    .line 101
    .local v3, "sign":[B
    if-nez v3, :cond_2

    move v5, v6

    goto :goto_1

    .line 103
    :cond_2
    :try_start_0
    invoke-static {p1}, Ljava/security/Signature;->getInstance(Ljava/lang/String;)Ljava/security/Signature;

    move-result-object v4

    .line 104
    .local v4, "signature":Ljava/security/Signature;
    const-string v5, "DSA"

    invoke-static {v5, p2}, Lrexsee/security/RexseeSignature;->string2publicKey_(Ljava/lang/String;Ljava/lang/String;)Ljava/security/PublicKey;

    move-result-object v2

    check-cast v2, Ljava/security/interfaces/DSAPublicKey;

    .line 105
    .local v2, "key":Ljava/security/interfaces/DSAPublicKey;
    invoke-virtual {v4, v2}, Ljava/security/Signature;->initVerify(Ljava/security/PublicKey;)V

    .line 106
    invoke-virtual {v4, v0}, Ljava/security/Signature;->update([B)V

    .line 107
    invoke-virtual {v4, v3}, Ljava/security/Signature;->verify([B)Z
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result v5

    goto :goto_1

    .line 108
    .end local v2    # "key":Ljava/security/interfaces/DSAPublicKey;
    .end local v4    # "signature":Ljava/security/Signature;
    :catch_0
    move-exception v5

    move-object v1, v5

    .local v1, "e":Ljava/lang/Exception;
    move v5, v6

    .line 109
    goto :goto_1
.end method

.method private verifyRSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Z
    .locals 7
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "publicKey"    # Ljava/lang/String;
    .param p3, "signatureString"    # Ljava/lang/String;
    .param p4, "string"    # Ljava/lang/String;
    .param p5, "isFile"    # Z

    .prologue
    const/4 v6, 0x0

    .line 83
    if-eqz p5, :cond_0

    invoke-static {p4}, Lrexsee/core/utilities/Utilities;->getContent(Ljava/lang/String;)[B

    move-result-object v5

    move-object v0, v5

    .line 84
    .local v0, "data":[B
    :goto_0
    if-nez v0, :cond_1

    move v5, v6

    .line 94
    :goto_1
    return v5

    .line 83
    .end local v0    # "data":[B
    :cond_0
    invoke-virtual {p4}, Ljava/lang/String;->getBytes()[B

    move-result-object v5

    move-object v0, v5

    goto :goto_0

    .line 85
    .restart local v0    # "data":[B
    :cond_1
    invoke-static {p3}, Lrexsee/security/RexseeSecurity;->hex2bytes(Ljava/lang/String;)[B

    move-result-object v3

    .line 86
    .local v3, "sign":[B
    if-nez v3, :cond_2

    move v5, v6

    goto :goto_1

    .line 88
    :cond_2
    :try_start_0
    invoke-static {p1}, Ljava/security/Signature;->getInstance(Ljava/lang/String;)Ljava/security/Signature;

    move-result-object v4

    .line 89
    .local v4, "signature":Ljava/security/Signature;
    const-string v5, "RSA"

    invoke-static {v5, p2}, Lrexsee/security/RexseeSignature;->string2publicKey_(Ljava/lang/String;Ljava/lang/String;)Ljava/security/PublicKey;

    move-result-object v2

    check-cast v2, Ljava/security/interfaces/RSAPublicKey;

    .line 90
    .local v2, "key":Ljava/security/interfaces/RSAPublicKey;
    invoke-virtual {v4, v2}, Ljava/security/Signature;->initVerify(Ljava/security/PublicKey;)V

    .line 91
    invoke-virtual {v4, v0}, Ljava/security/Signature;->update([B)V

    .line 92
    invoke-virtual {v4, v3}, Ljava/security/Signature;->verify([B)Z
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result v5

    goto :goto_1

    .line 93
    .end local v2    # "key":Ljava/security/interfaces/RSAPublicKey;
    .end local v4    # "signature":Ljava/security/Signature;
    :catch_0
    move-exception v5

    move-object v1, v5

    .local v1, "e":Ljava/lang/Exception;
    move v5, v6

    .line 94
    goto :goto_1
.end method


# virtual methods
.method public getInheritInterface(Lrexsee/core/browser/Browser;)Lrexsee/core/browser/clazz/JavascriptInterface;
    .locals 0
    .param p1, "childBrowser"    # Lrexsee/core/browser/Browser;

    .prologue
    .line 28
    return-object p0
.end method

.method public getInterfaceName()Ljava/lang/String;
    .locals 2

    .prologue
    .line 24
    new-instance v0, Ljava/lang/StringBuilder;

    iget-object v1, p0, Lrexsee/security/RexseeSignature;->mBrowser:Lrexsee/core/browser/Browser;

    iget-object v1, v1, Lrexsee/core/browser/Browser;->application:Lrexsee/core/application/RexseeApplication;

    iget-object v1, v1, Lrexsee/core/application/RexseeApplication;->resources:Lrexsee/core/application/Resource;

    iget-object v1, v1, Lrexsee/core/application/Resource;->prefix:Ljava/lang/String;

    invoke-static {v1}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v1

    invoke-direct {v0, v1}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v1, "Signature"

    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v0

    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public getNewInterface(Lrexsee/core/browser/Browser;)Lrexsee/core/browser/clazz/JavascriptInterface;
    .locals 1
    .param p1, "childBrowser"    # Lrexsee/core/browser/Browser;

    .prologue
    .line 32
    new-instance v0, Lrexsee/security/RexseeSignature;

    invoke-direct {v0, p1}, Lrexsee/security/RexseeSignature;-><init>(Lrexsee/core/browser/Browser;)V

    return-object v0
.end method

.method public signFileWithDSA(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 1
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "privateKey"    # Ljava/lang/String;
    .param p3, "path"    # Ljava/lang/String;

    .prologue
    .line 125
    const/4 v0, 0x1

    invoke-direct {p0, p1, p2, p3, v0}, Lrexsee/security/RexseeSignature;->signDSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public signFileWithRSA(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 1
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "privateKey"    # Ljava/lang/String;
    .param p3, "path"    # Ljava/lang/String;

    .prologue
    .line 119
    const/4 v0, 0x1

    invoke-direct {p0, p1, p2, p3, v0}, Lrexsee/security/RexseeSignature;->signRSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public signWithDSA(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 1
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "privateKey"    # Ljava/lang/String;
    .param p3, "string"    # Ljava/lang/String;

    .prologue
    .line 122
    const/4 v0, 0x0

    invoke-direct {p0, p1, p2, p3, v0}, Lrexsee/security/RexseeSignature;->signDSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public signWithRSA(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 1
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "privateKey"    # Ljava/lang/String;
    .param p3, "string"    # Ljava/lang/String;

    .prologue
    .line 116
    const/4 v0, 0x0

    invoke-direct {p0, p1, p2, p3, v0}, Lrexsee/security/RexseeSignature;->signRSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method public verifyFileWithDSA(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
    .locals 6
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "publicKey"    # Ljava/lang/String;
    .param p3, "signatureString"    # Ljava/lang/String;
    .param p4, "path"    # Ljava/lang/String;

    .prologue
    .line 138
    const/4 v5, 0x1

    move-object v0, p0

    move-object v1, p1

    move-object v2, p2

    move-object v3, p3

    move-object v4, p4

    invoke-direct/range {v0 .. v5}, Lrexsee/security/RexseeSignature;->verifyDSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Z

    move-result v0

    return v0
.end method

.method public verifyFileWithRSA(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
    .locals 6
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "publicKey"    # Ljava/lang/String;
    .param p3, "signatureString"    # Ljava/lang/String;
    .param p4, "path"    # Ljava/lang/String;

    .prologue
    .line 132
    const/4 v5, 0x1

    move-object v0, p0

    move-object v1, p1

    move-object v2, p2

    move-object v3, p3

    move-object v4, p4

    invoke-direct/range {v0 .. v5}, Lrexsee/security/RexseeSignature;->verifyRSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Z

    move-result v0

    return v0
.end method

.method public verifyWithDSA(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
    .locals 6
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "publicKey"    # Ljava/lang/String;
    .param p3, "signatureString"    # Ljava/lang/String;
    .param p4, "string"    # Ljava/lang/String;

    .prologue
    .line 135
    const/4 v5, 0x0

    move-object v0, p0

    move-object v1, p1

    move-object v2, p2

    move-object v3, p3

    move-object v4, p4

    invoke-direct/range {v0 .. v5}, Lrexsee/security/RexseeSignature;->verifyDSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Z

    move-result v0

    return v0
.end method

.method public verifyWithRSA(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z
    .locals 6
    .param p1, "algorithm"    # Ljava/lang/String;
    .param p2, "publicKey"    # Ljava/lang/String;
    .param p3, "signatureString"    # Ljava/lang/String;
    .param p4, "string"    # Ljava/lang/String;

    .prologue
    .line 129
    const/4 v5, 0x0

    move-object v0, p0

    move-object v1, p1

    move-object v2, p2

    move-object v3, p3

    move-object v4, p4

    invoke-direct/range {v0 .. v5}, Lrexsee/security/RexseeSignature;->verifyRSA_(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)Z

    move-result v0

    return v0
.end method
